package guoanmaker.operator.business.service;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import guoanmaker.operator.business.model.OperatorHotServer;
import guoanmaker.operator.business.model.OperatorHotServerPc;
import guoanmaker.operator.business.model.OperatorServerClass;
import guoanmaker.operator.business.repository.OperatorHotServerPcRepository;
import guoanmaker.operator.business.repository.OperatorServerClassRepository;

@Service
public class OperatorHotServerPcService implements OperatorHotServerPcServiceIntegerface {
	 @PersistenceContext
		private EntityManager manager;
	 @Autowired
	 private OperatorHotServerPcRepository operatorHotServerPcRepository;
	 @Autowired
	 private  OperatorServerClassRepository operatorServerClassRepository;
	 @Transactional
	  public void delectAllBycitycode(String cityId){
		  String jpql="delete  from OperatorHotServerPc  u where u.cityId=:cityId";
		  Query query2=manager.createQuery(jpql);//查询商品提供的服务区域
			query2.setParameter("cityId", cityId);
			query2.executeUpdate();
		  
	  }
	@Override
	public OperatorHotServerPc saveHotServer(OperatorHotServerPc operatorHotServerPc) {
		// TODO Auto-generated method stub
		return operatorHotServerPcRepository.save(operatorHotServerPc);
	}
	 public List<OperatorHotServerPc> getAllAndServerName(String cityId) {
	        List<OperatorHotServerPc> servers = operatorHotServerPcRepository.findBycityCode(cityId);
	       /* for(OperatorHotServerPc server:servers){
	        	 OperatorServerClass serverClass=	operatorServerClassRepository.findOne(server.getServiceTwoId());
	        	 server.setServerName(serverClass.getServerName());
	        }*/
	        return servers;
	    }
	
	 @Override
	    @Transactional
	    public void deleteHotServerById(String id) {
		 operatorHotServerPcRepository.delete(id);
	    }
}
